<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <?php
        include '../../color_style.php';
        include '../../'.LANGUAGE;
        echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">';
    ?>
    <title></title>
</head>
<body bgcolor="#DFDFDF"><div align="center">
    <?php
        require_once("plugins/CBO/ItemFolder.php");
        require_once("plugins/CBO/ItemImageFile.php");
            
        require_once("definitions.inc.php");
        require_once("plugins/filesystem/classFileSystem.inc.php");
        require_once("plugins/imageviewer/classImageViewerXMLService.inc.php");
        
        require_once("plugins/DAL/DirDataAdapter.php");
        require_once("plugins/DAL/FileDataAdapter.php");
        require_once("plugins/BLL/DirManager.php");
        require_once("plugins/BLL/FileManager.php");
        require_once("plugins/PTL/DirPresentation.php");
        require_once("plugins/PTL/FilePresentation.php");
        
        $_fileSystem = new classFileSystem();
        $ItemFolder = new ItemFolder(); 
        $ItemImageFile = new ItemImageFile();
        $FilePresentation = new FilePresentation();
        $DirPresentation = new DirPresentation();
        
        $baseDir = "../../../data/photoalbums/";
        $dirs = $_fileSystem->getDirsList($baseDir);
        
        $selectedDir = $DirPresentation->ReqSELECTED();
        
        if($selectedDir=="")
          $selectedDir = $dirs[0];
        $dirname = $baseDir.$selectedDir.'/';
        $FileManager = new FileManager($selectedDir);   
        $DirManager = new DirManager($selectedDir);
               
        $ItemFileInsert = $FilePresentation->ReqINSERT(&$source_filename);
        $ItemFileUpdate = $FilePresentation->ReqUPDATE();
        $NameFileDelete = $FilePresentation->ReqDELETE();
            
        if($ItemFileInsert != "")
            $FileManager->InsertItem($ItemFileInsert, $source_filename);
            
        if($ItemFileUpdate != "")
            $FileManager->UpdateItem($ItemFileUpdate);
        
        if($NameFileDelete != "")
            $FileManager->DeleteItem($NameFileDelete);
         
        
        $ItemDirInsert = $DirPresentation->ReqINSERT();
        $ItemDirUpdate = $DirPresentation->ReqUPDATE(&$OldDirname);
        $NameDirDelete = $DirPresentation->ReqDELETE();
        
        if($ItemDirInsert != "")
            $DirManager->InsertItem($ItemDirInsert);
        
        if($ItemDirUpdate != "")
            $DirManager->UpdateItem($ItemDirUpdate,$OldDirname);
            
        if($NameDirDelete != "")
           { $DirManager->DeleteItem($NameDirDelete);
             $selectedDir = $dirs[0];
             $dirname = $baseDir.$selectedDir.'/';
             $FileManager = new FileManager($selectedDir);   
             $DirManager = new DirManager($selectedDir);
           }
        
        
        $ItemFolder = $DirManager->SelectItem();
        
        
        $dirs = $_fileSystem->getDirsList($baseDir);
        $DirPresentation->Insert();
        
        if($dirs != "")
        {
            $DirPresentation->Select($dirs,$selectedDir);
            $DirPresentation->Update($ItemFolder);
            $FilePresentation->Insert($selectedDir);
        }
        
        if($ItemFolder->ImageFileList != "")
            $FilePresentation->Grid($ItemFolder->ImageFileList, $ItemFolder->dirName);
  
                            
    ?>
</div>
</body>
</html>
